package com.yy.micro.magic.exception;

public class MapException extends RuntimeException{

    private ExceptionCategory category = ExceptionCategory.NONE;

    private String strategy;

    public MapException(){
        super();
    }

    public MapException(String message){
        super(message);
    }

    public MapException(ExceptionCategory category,String message){
        super(message);
        if (null != category){
            this.category = category;
        }
    }

    public MapException(String message,Throwable throwable){
        super(message,throwable);
    }

    public MapException(Throwable throwable){
        super(throwable);
        this.category = ExceptionCategory.RUNTIME;
    }

    public MapException setStrategy(final String strategy) {
        this.strategy = strategy;
        return this;
    }

    public ExceptionCategory getCategory() {
        return category;
    }

    public boolean isBlock(){
        return null ==category?true:category.isBlock();
    }

    public static MapException create(String message){
        return create(message,null,ExceptionCategory.RUNTIME);
    }

    public static MapException create(Throwable throwable){
        return create(throwable.getMessage(),throwable,ExceptionCategory.RUNTIME);
    }

    public static MapException create(String message,ExceptionCategory category){
        return create(message,null,category);
    }

    public static MapException create(String message,Throwable throwable,ExceptionCategory category){
        MapException e = null;
        if (null ==throwable){
            e= new MapException(message);
        }else {
            e= new MapException(message,throwable);
        }
        e.category=category;
        return e;
    }
}
